{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "# 指数以及ETF相关数据"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "outputs": [],
   "source": [
    "import optshare"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## 返回当前指数以及ETF数据\n",
    "支持沪深重要指数、上证指数、深证系列指数、中证系列指数（包括指数成分），以及全部ETF数据"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [
    {
     "data": {
      "text/plain": "          代码         名称       最新价     涨跌幅      涨跌额         成交量           成交额  \\\n0     H50009      180通信  1931.800   5.23%   95.960   8847164.0  6.761367e+09   \n1     000916      300通信  2700.810   5.03%  129.310  11439811.0  1.189038e+10   \n2     513260  恒生科技ETFQD     1.095   4.29%    0.045    291114.0  3.146036e+07   \n3     931523    SHS动漫游戏   739.630   4.16%   29.510  16447347.0  1.851711e+10   \n4     513380  恒生科技ETF指数     1.063   4.11%    0.042    765805.0  8.035631e+07   \n...      ...        ...       ...     ...      ...         ...           ...   \n2166  930773      100反向  1522.880  -1.07%  -16.540  40487284.0  7.262403e+10   \n2167  159933  国投金融地产ETF     2.245  -1.54%   -0.035       236.0  5.288090e+04   \n2168  399691       创业专利  2515.510  -1.63%  -41.620   2791766.0  5.360747e+09   \n2169  H50047      180反两   515.620  -2.03%  -10.710  53416293.0  7.596210e+10   \n2170  930774      100反两   197.030  -2.16%   -4.350  40487284.0  7.262403e+10   \n\n        振幅        最高        最低        今开        昨收    量比  \n0     6.86  1949.670  1823.790  1830.480  1835.840  2.60  \n1     5.74  2715.470  2567.860  2568.690  2571.500  2.38  \n2     3.33     1.095     1.060     1.061     1.050  3.61  \n3     4.28   740.860   710.460   710.890   710.120  2.30  \n4     3.72     1.063     1.025     1.025     1.021  1.94  \n...    ...       ...       ...       ...       ...   ...  \n2166  1.32  1541.840  1521.550  1538.230  1539.420  1.59  \n2167  1.18     2.257     2.230     2.230     2.280  0.78  \n2168  1.47  2542.980  2505.270  2542.670  2557.130  1.76  \n2169  2.56   527.750   514.300   526.020   526.330  1.47  \n2170  2.64   201.990   196.680   201.040   201.380  1.59  \n\n[2171 rows x 13 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>代码</th>\n      <th>名称</th>\n      <th>最新价</th>\n      <th>涨跌幅</th>\n      <th>涨跌额</th>\n      <th>成交量</th>\n      <th>成交额</th>\n      <th>振幅</th>\n      <th>最高</th>\n      <th>最低</th>\n      <th>今开</th>\n      <th>昨收</th>\n      <th>量比</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>H50009</td>\n      <td>180通信</td>\n      <td>1931.800</td>\n      <td>5.23%</td>\n      <td>95.960</td>\n      <td>8847164.0</td>\n      <td>6.761367e+09</td>\n      <td>6.86</td>\n      <td>1949.670</td>\n      <td>1823.790</td>\n      <td>1830.480</td>\n      <td>1835.840</td>\n      <td>2.60</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>000916</td>\n      <td>300通信</td>\n      <td>2700.810</td>\n      <td>5.03%</td>\n      <td>129.310</td>\n      <td>11439811.0</td>\n      <td>1.189038e+10</td>\n      <td>5.74</td>\n      <td>2715.470</td>\n      <td>2567.860</td>\n      <td>2568.690</td>\n      <td>2571.500</td>\n      <td>2.38</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>513260</td>\n      <td>恒生科技ETFQD</td>\n      <td>1.095</td>\n      <td>4.29%</td>\n      <td>0.045</td>\n      <td>291114.0</td>\n      <td>3.146036e+07</td>\n      <td>3.33</td>\n      <td>1.095</td>\n      <td>1.060</td>\n      <td>1.061</td>\n      <td>1.050</td>\n      <td>3.61</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>931523</td>\n      <td>SHS动漫游戏</td>\n      <td>739.630</td>\n      <td>4.16%</td>\n      <td>29.510</td>\n      <td>16447347.0</td>\n      <td>1.851711e+10</td>\n      <td>4.28</td>\n      <td>740.860</td>\n      <td>710.460</td>\n      <td>710.890</td>\n      <td>710.120</td>\n      <td>2.30</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>513380</td>\n      <td>恒生科技ETF指数</td>\n      <td>1.063</td>\n      <td>4.11%</td>\n      <td>0.042</td>\n      <td>765805.0</td>\n      <td>8.035631e+07</td>\n      <td>3.72</td>\n      <td>1.063</td>\n      <td>1.025</td>\n      <td>1.025</td>\n      <td>1.021</td>\n      <td>1.94</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>2166</th>\n      <td>930773</td>\n      <td>100反向</td>\n      <td>1522.880</td>\n      <td>-1.07%</td>\n      <td>-16.540</td>\n      <td>40487284.0</td>\n      <td>7.262403e+10</td>\n      <td>1.32</td>\n      <td>1541.840</td>\n      <td>1521.550</td>\n      <td>1538.230</td>\n      <td>1539.420</td>\n      <td>1.59</td>\n    </tr>\n    <tr>\n      <th>2167</th>\n      <td>159933</td>\n      <td>国投金融地产ETF</td>\n      <td>2.245</td>\n      <td>-1.54%</td>\n      <td>-0.035</td>\n      <td>236.0</td>\n      <td>5.288090e+04</td>\n      <td>1.18</td>\n      <td>2.257</td>\n      <td>2.230</td>\n      <td>2.230</td>\n      <td>2.280</td>\n      <td>0.78</td>\n    </tr>\n    <tr>\n      <th>2168</th>\n      <td>399691</td>\n      <td>创业专利</td>\n      <td>2515.510</td>\n      <td>-1.63%</td>\n      <td>-41.620</td>\n      <td>2791766.0</td>\n      <td>5.360747e+09</td>\n      <td>1.47</td>\n      <td>2542.980</td>\n      <td>2505.270</td>\n      <td>2542.670</td>\n      <td>2557.130</td>\n      <td>1.76</td>\n    </tr>\n    <tr>\n      <th>2169</th>\n      <td>H50047</td>\n      <td>180反两</td>\n      <td>515.620</td>\n      <td>-2.03%</td>\n      <td>-10.710</td>\n      <td>53416293.0</td>\n      <td>7.596210e+10</td>\n      <td>2.56</td>\n      <td>527.750</td>\n      <td>514.300</td>\n      <td>526.020</td>\n      <td>526.330</td>\n      <td>1.47</td>\n    </tr>\n    <tr>\n      <th>2170</th>\n      <td>930774</td>\n      <td>100反两</td>\n      <td>197.030</td>\n      <td>-2.16%</td>\n      <td>-4.350</td>\n      <td>40487284.0</td>\n      <td>7.262403e+10</td>\n      <td>2.64</td>\n      <td>201.990</td>\n      <td>196.680</td>\n      <td>201.040</td>\n      <td>201.380</td>\n      <td>1.59</td>\n    </tr>\n  </tbody>\n</table>\n<p>2171 rows × 13 columns</p>\n</div>"
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "optshare.get_current_index()"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## 获取日频数据\n",
    "支持指数、ETF、个股，根据代码以及指定日期区间，返回历史时段内的相应指数信息"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [
    {
     "data": {
      "text/plain": "            日期       开盘       收盘       最高       最低        成交量           成交额  \\\n0   2023-01-03  3864.84  3887.90  3893.99  3831.25  115051875  2.075402e+11   \n1   2023-01-04  3886.25  3892.95  3905.90  3873.65  110660743  1.989977e+11   \n2   2023-01-05  3913.49  3968.58  3974.88  3912.26  116502395  2.563126e+11   \n3   2023-01-06  3969.55  3980.89  4000.41  3966.47  110953038  2.357443e+11   \n4   2023-01-09  3998.53  4013.12  4023.09  3990.71  117054425  2.332124e+11   \n5   2023-01-10  4014.71  4017.47  4030.46  4002.23  101751141  2.148712e+11   \n6   2023-01-11  4019.88  4010.03  4043.40  4008.02   99997889  2.030003e+11   \n7   2023-01-12  4021.75  4017.87  4030.29  4003.51   90552627  1.836863e+11   \n8   2023-01-13  4032.29  4074.38  4074.38  4027.89   95871896  2.121740e+11   \n9   2023-01-16  4077.88  4137.96  4177.10  4076.64  151395455  3.190077e+11   \n10  2023-01-17  4138.84  4137.24  4148.58  4118.16   95479040  2.043816e+11   \n11  2023-01-18  4140.10  4130.31  4151.46  4125.77   84200645  1.721262e+11   \n\n      振幅   涨跌幅    涨跌额   换手率  \n0   1.62  0.42  16.27  0.40  \n1   0.83  0.13   5.05  0.38  \n2   1.61  1.94  75.63  0.40  \n3   0.86  0.31  12.31  0.38  \n4   0.81  0.81  32.23  0.40  \n5   0.70  0.11   4.35  0.35  \n6   0.88 -0.19  -7.44  0.35  \n7   0.67  0.20   7.84  0.31  \n8   1.16  1.41  56.51  0.33  \n9   2.47  1.56  63.58  0.52  \n10  0.74 -0.02  -0.72  0.33  \n11  0.62 -0.17  -6.93  0.29  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>日期</th>\n      <th>开盘</th>\n      <th>收盘</th>\n      <th>最高</th>\n      <th>最低</th>\n      <th>成交量</th>\n      <th>成交额</th>\n      <th>振幅</th>\n      <th>涨跌幅</th>\n      <th>涨跌额</th>\n      <th>换手率</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>2023-01-03</td>\n      <td>3864.84</td>\n      <td>3887.90</td>\n      <td>3893.99</td>\n      <td>3831.25</td>\n      <td>115051875</td>\n      <td>2.075402e+11</td>\n      <td>1.62</td>\n      <td>0.42</td>\n      <td>16.27</td>\n      <td>0.40</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2023-01-04</td>\n      <td>3886.25</td>\n      <td>3892.95</td>\n      <td>3905.90</td>\n      <td>3873.65</td>\n      <td>110660743</td>\n      <td>1.989977e+11</td>\n      <td>0.83</td>\n      <td>0.13</td>\n      <td>5.05</td>\n      <td>0.38</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>2023-01-05</td>\n      <td>3913.49</td>\n      <td>3968.58</td>\n      <td>3974.88</td>\n      <td>3912.26</td>\n      <td>116502395</td>\n      <td>2.563126e+11</td>\n      <td>1.61</td>\n      <td>1.94</td>\n      <td>75.63</td>\n      <td>0.40</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>2023-01-06</td>\n      <td>3969.55</td>\n      <td>3980.89</td>\n      <td>4000.41</td>\n      <td>3966.47</td>\n      <td>110953038</td>\n      <td>2.357443e+11</td>\n      <td>0.86</td>\n      <td>0.31</td>\n      <td>12.31</td>\n      <td>0.38</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>2023-01-09</td>\n      <td>3998.53</td>\n      <td>4013.12</td>\n      <td>4023.09</td>\n      <td>3990.71</td>\n      <td>117054425</td>\n      <td>2.332124e+11</td>\n      <td>0.81</td>\n      <td>0.81</td>\n      <td>32.23</td>\n      <td>0.40</td>\n    </tr>\n    <tr>\n      <th>5</th>\n      <td>2023-01-10</td>\n      <td>4014.71</td>\n      <td>4017.47</td>\n      <td>4030.46</td>\n      <td>4002.23</td>\n      <td>101751141</td>\n      <td>2.148712e+11</td>\n      <td>0.70</td>\n      <td>0.11</td>\n      <td>4.35</td>\n      <td>0.35</td>\n    </tr>\n    <tr>\n      <th>6</th>\n      <td>2023-01-11</td>\n      <td>4019.88</td>\n      <td>4010.03</td>\n      <td>4043.40</td>\n      <td>4008.02</td>\n      <td>99997889</td>\n      <td>2.030003e+11</td>\n      <td>0.88</td>\n      <td>-0.19</td>\n      <td>-7.44</td>\n      <td>0.35</td>\n    </tr>\n    <tr>\n      <th>7</th>\n      <td>2023-01-12</td>\n      <td>4021.75</td>\n      <td>4017.87</td>\n      <td>4030.29</td>\n      <td>4003.51</td>\n      <td>90552627</td>\n      <td>1.836863e+11</td>\n      <td>0.67</td>\n      <td>0.20</td>\n      <td>7.84</td>\n      <td>0.31</td>\n    </tr>\n    <tr>\n      <th>8</th>\n      <td>2023-01-13</td>\n      <td>4032.29</td>\n      <td>4074.38</td>\n      <td>4074.38</td>\n      <td>4027.89</td>\n      <td>95871896</td>\n      <td>2.121740e+11</td>\n      <td>1.16</td>\n      <td>1.41</td>\n      <td>56.51</td>\n      <td>0.33</td>\n    </tr>\n    <tr>\n      <th>9</th>\n      <td>2023-01-16</td>\n      <td>4077.88</td>\n      <td>4137.96</td>\n      <td>4177.10</td>\n      <td>4076.64</td>\n      <td>151395455</td>\n      <td>3.190077e+11</td>\n      <td>2.47</td>\n      <td>1.56</td>\n      <td>63.58</td>\n      <td>0.52</td>\n    </tr>\n    <tr>\n      <th>10</th>\n      <td>2023-01-17</td>\n      <td>4138.84</td>\n      <td>4137.24</td>\n      <td>4148.58</td>\n      <td>4118.16</td>\n      <td>95479040</td>\n      <td>2.043816e+11</td>\n      <td>0.74</td>\n      <td>-0.02</td>\n      <td>-0.72</td>\n      <td>0.33</td>\n    </tr>\n    <tr>\n      <th>11</th>\n      <td>2023-01-18</td>\n      <td>4140.10</td>\n      <td>4130.31</td>\n      <td>4151.46</td>\n      <td>4125.77</td>\n      <td>84200645</td>\n      <td>1.721262e+11</td>\n      <td>0.62</td>\n      <td>-0.17</td>\n      <td>-6.93</td>\n      <td>0.29</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "optshare.get_daily_data('000300', start_date = '20230101', end_date = '20230118')"
   ],
   "metadata": {
    "collapsed": false
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
